{% extends 'accounts/base.html' %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">{{ title }}</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
        <div class="btn-group me-2">
            <a href="{% url 'tools:tool_list' %}" class="btn btn-sm btn-outline-secondary">
                <i class="fas fa-arrow-left"></i> 返回列表
            </a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="card">
            <div class="card-body">
                <form method="post">
                    {% csrf_token %}
                    
                    {% if form.non_field_errors %}
                    <div class="alert alert-danger">
                        {{ form.non_field_errors }}
                    </div>
                    {% endif %}
                    
                    <div class="mb-3">
                        <label for="{{ form.name.id_for_label }}" class="form-label">工具名称 *</label>
                        {{ form.name }}
                        {% if form.name.errors %}
                        <div class="text-danger">{{ form.name.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="{{ form.version.id_for_label }}" class="form-label">版本号</label>
                        {{ form.version }}
                        {% if form.version.errors %}
                        <div class="text-danger">{{ form.version.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="{{ form.category.id_for_label }}" class="form-label">分类</label>
                        {{ form.category }}
                        {% if form.category.errors %}
                        <div class="text-danger">{{ form.category.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="{{ form.calibrated_date.id_for_label }}" class="form-label">校准日期</label>
                        {{ form.calibrated_date }}
                        {% if form.calibrated_date.errors %}
                        <div class="text-danger">{{ form.calibrated_date.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="{{ form.owner.id_for_label }}" class="form-label">工具所有人</label>
                        {{ form.owner }}
                        {% if form.owner.errors %}
                        <div class="text-danger">{{ form.owner.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="{{ form.url.id_for_label }}" class="form-label">工具链接</label>
                        {{ form.url }}
                        {% if form.url.errors %}
                        <div class="text-danger">{{ form.url.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="{{ form.description.id_for_label }}" class="form-label">工具描述</label>
                        {{ form.description }}
                        {% if form.description.errors %}
                        <div class="text-danger">{{ form.description.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3 form-check">
                        {{ form.is_active }}
                        <label for="{{ form.is_active.id_for_label }}" class="form-check-label">是否启用</label>
                        {% if form.is_active.errors %}
                        <div class="text-danger">{{ form.is_active.errors }}</div>
                        {% endif %}
                    </div>
                    
                    <div class="d-grid">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> 保存
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}